package vip.meeet.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@Controller
@RequestMapping("/list")
public class ListController {

    private static final String ROOT = "D:\\mydata";

    @RequestMapping("/first")
    public String fileBean(
            Model model,
            @RequestParam("name") String name
    ) throws IOException {
        Path path = Paths.get(ROOT,name);
        List<String> datas = Files.readAllLines(path);
        model.addAttribute("datas",datas);
        return "list/list-first";
    }

    @RequestMapping("/card")
    public String cardList(
            Model model,
            @RequestParam("name") String name
    ) throws IOException {
        Path path = Paths.get(ROOT,name);
        List<String> datas = Files.readAllLines(path);
        model.addAttribute("datas",datas);
        return "list/card-list";
    }

}
